<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <#include "../../common/header.ftl">

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.css">
    <!-- Latest compiled and minified JavaScript -->
    <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.js"></script>
    <!-- Latest compiled and minified Locales -->
    <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.min.js"></script>
</head>
<body>
<div class="container-fluid">
    <#include "../../common/left-nav.ftl">

    <div class="main-box">
        <ol class="breadcrumb crumbs">
            <li><a href="#">个人中心</a></li>
        </ol>

        <div class="container-fluid">
            <div class="panel panel-info" style="margin-top: 20px;">
                <div class="panel-heading"><b>密码修改</b></div>
                <div class="panel-body">
                    <form class="form-horizontal" id="dataForm">

                        <div class="form-group">
                            <label for="oldPwd" class="col-sm-2 control-label">旧密码</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="oldPwd" id="oldPwd"
                                       placeholder="请输入旧密码" maxlength="16" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="newPwd" class="col-sm-2 control-label">新密码</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="newPwd" id="newPwd"
                                       placeholder="请输入新的密码，6个字符长度以上" maxlength="16" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="rePwd" class="col-sm-2 control-label">重复密码</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="rePwd" id="rePwd"
                                       placeholder="请确认输入新密码" maxlength="16" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>


    </div>
</div>
</body>
</html>

<script type="text/javascript">
    $(document).ready(function () {
        $('#dataForm').submit(function (e) {
            var target = e.target;

            var formData = {};

            var fieldInputs = $(target).find('input');
            for (var i = 0; i < fieldInputs.length; i++) {
                var item = fieldInputs[i];
                if (item.name && item.name !== '') {
                    formData[item.name] = item.value;
                }
            }

            if (formData.newPwd.length < 6) {
                bootbox.alert("密码长度小于6位，请重新输入");
                return false;
            }

            if (formData.newPwd !== formData.rePwd) {
                bootbox.alert("两次密码输入不一致，请重新输入");
                return false;
            }

            $.httpclient.put(API_MEMBER + '/pwd', JSON.stringify(formData), function (data) {
                location.href = ctx + '/admin/home';
            });

            return false;
        })
    })
</script>